Skip to content

fix(scanner): drop warn advisories in non-interactive mode#2

Merged
muneebs merged 2 commits intomainfrom
fix/no-tty-in-ci
Apr 23, 2026
Merged

fix(scanner): drop warn advisories in non-interactive mode#2
muneebs merged 2 commits intomainfrom
fix/no-tty-in-ci

Conversation

@muneebs
Copy link
Copy Markdown
Owner

@muneebs muneebs commented Apr 23, 2026

Summary

  • bun install with CI=true (or any non-TTY environment) was hanging on the Continue anyway? [y/N] prompt whenever the scanner returned any warn-level advisories. Per Bun's docs warns should "immediately exit if not [a TTY]" — in practice they were blocking installs.
  • New stripNonBlockingInCI() filter drops warn-level advisories from the scanner's return value when CI=true or stdin is not a TTY, logging each to stderr so they remain visible. fatal advisories continue to block.
  • Default test suite now forces interactive mode in beforeEach (so the existing severity-mapping tests still see warns), with a new dedicated test covering the non-interactive strip behavior.

Test plan

  • bun test (86 pass)
  • Verify in a real CI install that bun install --frozen-lockfile no longer hangs when only warn-level advisories are returned
  • Confirm fatal advisories still abort the install in CI

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Advisory filtering behavior has been updated for CI and non-interactive environments. Warn-level security advisories are now filtered from blocking results, while fatal advisories continue to block builds. Advisories filtered out are logged to stderr.
  • Tests

    • Added tests to verify correct advisory filtering behavior in non-interactive and CI modes across different scanning scenarios.

Bun prompts ("Continue anyway? [y/N]") whenever the scanner returns any
warn-level advisory. In CI / non-TTY environments this either hangs the
install or auto-cancels it, even though warns are not supposed to block.

Strip warn-level advisories from the scanner's return value when
CI=true or stdin is not a TTY, logging each to stderr so they remain
visible. Fatal advisories continue to block as before.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

Warning

Rate limit exceeded

@muneebs has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 54 minutes and 41 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 54 minutes and 41 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b098668a-657d-4bab-9790-961690319537

📥 Commits

Reviewing files that changed from the base of the PR and between f23497f and 8069140.

📒 Files selected for processing (1)
  • src/__tests__/scanner.test.ts

Walkthrough

Test suite now enforces interactive-mode environment through process.env.CI and process.stdin.isTTY overrides, while scanner logic introduces stripNonBlockingInCI function to filter warn-level advisories in CI/non-interactive sessions, retaining only fatal advisories and logging dropped warnings.

Changes

Cohort / File(s) Summary
Test Infrastructure
src/__tests__/scanner.test.ts
Explicit setup/teardown for interactive-mode environment variables within scanner.scan test suite; new test case validates that warn-level advisories are excluded in CI mode (CI='true', isTTY=false) while fatal advisories remain.
Scanner Logic
src/scanner.ts
Introduces stripNonBlockingInCI helper function that removes level === 'warn' advisories and logs them to stderr in non-interactive environments; applied across three control-flow paths (cached-only, successful fetch, error handling).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hops of glee through the code so neat,
Warnings filtered in CI's beat,
Only fatals block the way,
Tests confirm it day by day! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'fix(scanner): drop warn advisories in non-interactive mode' clearly and specifically describes the main change: removing warn-level advisories in CI/non-interactive environments.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/no-tty-in-ci

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/scanner.ts (1)

102-118: Consider extracting an isInteractive() helper.

The interactive detection logic here (lines 105-106) is duplicated verbatim in applyIgnores (lines 136-137). Extracting a small helper would keep the two call sites in lockstep if the heuristic ever evolves (e.g., NO_TTY, FORCE_COLOR, GITHUB_ACTIONS, etc.).

♻️ Proposed refactor
+function isInteractive(): boolean {
+  return process.env.CI !== 'true' && (process.stdin?.isTTY ?? false);
+}
+
 function stripNonBlockingInCI(
   advisories: Bun.Security.Advisory[]
 ): Bun.Security.Advisory[] {
-  const interactive =
-    process.env.CI !== 'true' && (process.stdin?.isTTY ?? false);
-  if (interactive) return advisories;
+  if (isInteractive()) return advisories;

And similarly in applyIgnores.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/scanner.ts` around lines 102 - 118, Duplicate interactive-detection logic
exists in stripNonBlockingInCI and applyIgnores; extract a small helper function
(e.g., isInteractive or isTTYInteractive) that implements const interactive =
process.env.CI !== 'true' && (process.stdin?.isTTY ?? false) and replace the
duplicated lines in both stripNonBlockingInCI and applyIgnores with a call to
that helper so both call sites stay in sync; place the helper near the top of
src/scanner.ts (export only if needed) and ensure existing behavior/logging is
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/__tests__/scanner.test.ts`:
- Around line 96-100: The test teardown currently tries to restore
process.stdin.isTTY by assigning undefined when origIsTTYDescriptor is falsy,
which throws in CI because isTTY is non-writable; update the cleanup in
scanner.test.ts to, if origIsTTYDescriptor exists call
Object.defineProperty(process.stdin, 'isTTY', origIsTTYDescriptor) (as already
done), otherwise remove the property using Reflect.deleteProperty(process.stdin,
'isTTY') instead of assigning undefined — reference the origIsTTYDescriptor
variable and the process.stdin.isTTY restoration logic to locate the fix.

---

Nitpick comments:
In `@src/scanner.ts`:
- Around line 102-118: Duplicate interactive-detection logic exists in
stripNonBlockingInCI and applyIgnores; extract a small helper function (e.g.,
isInteractive or isTTYInteractive) that implements const interactive =
process.env.CI !== 'true' && (process.stdin?.isTTY ?? false) and replace the
duplicated lines in both stripNonBlockingInCI and applyIgnores with a call to
that helper so both call sites stay in sync; place the helper near the top of
src/scanner.ts (export only if needed) and ensure existing behavior/logging is
unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 85688b24-20ab-41d8-8d1f-454f2e7ca93b

📥 Commits

Reviewing files that changed from the base of the PR and between 2b6e03f and f23497f.

📒 Files selected for processing (2)
  • src/__tests__/scanner.test.ts
  • src/scanner.ts

Comment thread src/__tests__/scanner.test.ts
@muneebs muneebs merged commit 2d86589 into main Apr 23, 2026
7 checks passed
@muneebs muneebs deleted the fix/no-tty-in-ci branch April 23, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant